package socketEnv;

import java.io.*;

/**
 * Created by hanyz on 2017/1/4.
 */
class InputStreamRunnable implements Runnable
{
    BufferedReader bReader=null;
    String type=null;
    String lineSeparator = "\n";
    public InputStreamRunnable(InputStream is, String type)
    {
        lineSeparator = System.getProperty("line.separator");
        this.type = type;
        try
        {
            bReader=new BufferedReader(new InputStreamReader(new BufferedInputStream(is),"GB2312"));
        }
        catch(Exception e)
        {
        }
    }
    public void run()
    {
        String line;
        FileOutputStream out = null;
        try
        {
            out = new FileOutputStream(new File(type+".txt"));
            OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(out), "GB2312");
            while((line=bReader.readLine())!=null) {
                writer.write(line+lineSeparator);
                writer.flush();
            }
        }
        catch(Exception ex)
        {
        }finally {
            if(out != null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}